<template>
  <div id="centreRight1">
    <div class="bg-color-black">
      <div class="d-flex pt-2 pl-2">
        <span style="color:#5cd9e8">
          <icon name="chart-line"></icon>
        </span>
        <div class="d-flex">
          <span class="fs-xl text mx-2">空间月度用电增长率</span>
        </div>
      </div>
      <dv-decoration-4 :reverse="true" style="width:100%;height:5px;" />
      <div class="d-flex jc-center body-box">
        <dv-scroll-board :config="config" style="width:3.20rem;height:3.98rem" />
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    chartData: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      isSetted:false,
      config: {
        header: ["空间", "变化率"],
        data: null,
        rowNum: 4, //表格行数
        headerHeight: 35,
        headerBGC: "#0f1325", //表头
        oddRowBGC: "#0f1325", //奇数行
        evenRowBGC: "#171c33", //偶数行
        index: true,
        columnWidth: [50],
        align: ["center"]
      }
    };
  },
  watch: {
    chartData: {
      handler ({placeRates} = {}) {
        if (this.isSetted){ return}
        this.isSetted = true
       this.config= {
          header: ["空间", "变化率"],
          data:(function(){
            const array = []
           for(const place of placeRates){
             if (place.rate >= 0) {
               array.push([place.place.name, "<span  class='colorGrass'>↑"+Math.abs(place.rate) +"%</span>"])
             }else{
               array.push([place.place.name, "<span  class='colorRed'>↓"+Math.abs(place.rate)+"%</span>"])
             }
           }
           return array
         })(),
         rowNum: 4, //表格行数
         headerHeight: 35,
         headerBGC: "#0f1325", //表头
         oddRowBGC: "#0f1325", //奇数行
         evenRowBGC: "#171c33", //偶数行
         index: true,
         columnWidth: [50],
         align: ["center"]
        }
      },
      immediate: true,
      deep: true
    }
  },
  components: {},
  mounted() {},
  methods: {}
};
</script>

<style lang="scss">
#centreRight1 {
  padding: 0.2rem;
  height: 5.125rem;
  min-width: 3.75rem;
  border-radius: 0.0625rem;
  .bg-color-black {
    height: 4.8125rem;
    border-radius: 0.125rem;
  }
  .text {
    color: #c3cbde;
  }
  .body-box {
    border-radius: 0.125rem;
    overflow: hidden;
  }
}
</style>
